<?php
# ***** BEGIN LICENSE BLOCK *****
# This file is a contributed part of DotClear.
# Copyright (c) 2005 Boris de Laage. All rights reserved.
#
# DotClear is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# DotClear is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with DotClear; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# ***** END LICENSE BLOCK *****

require_once(dirname(__FILE__).'/libascrobbler.php');

class dcScrobbler {

	function getTracks($count=0, $show_logo = true, $links = true, $maxlen=0, $itemfmt='%1$s - %2$s') {
		$scrob = dcScrobblerPlugin::getInstance();
		$tracks = $scrob->getTracks();
		/* --- deprecated ---
		$maxlen = $scrob->getMaxLineLength(); */
		$i = 0;
		
			
		echo '<ul>';
		if (!is_array($tracks) || sizeof($tracks) == 0)
            echo '<li><em>No recent tracks</em></li>';
        else {
        
            foreach($tracks as $track) {
            
                if ($count > 0 && ++$i > $count)
                    break;
				
                $str = sprintf($itemfmt, $track['artist'], $track['name']);
                $title = $track['artist'].' - '.$track['name'];
                if ($maxlen > 0 && strlen($str) > $maxlen)
                    $str = substr($str, 0, $maxlen -3) . '...';
                
                echo '<li>';
                if ($links)
					echo '<a href="'.$track['url'].'" title="'.$title.'">' .
						 $str . '</a>';
				else
					echo $str;
                echo '</li>';
            }
        }
		echo '</ul>';
		if ($show_logo) {
			/* FIXME ! */
			echo '<br />';
			echo '<a href="http://www.last.fm/user/' . $scrob->getUserName() .'">';
			echo '<img id="dcscrobblerlogo" src="/ecrire/tools/dcscrobbler/lastfm_button.png" alt="Last.fm" /></a>';
		}
	}
}
?>
